home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_emacs.idb / usr / freeware / share / emacs / 19.34 / lisp / winnt.el.z / winnt.el
Encoding:
Text File  |  1998-10-28  |  6.4 KB  |  198 lines

  1. ;;; winnt.el --- Lisp routines for Windows NT.
  2.  
  3. ;; Copyright (C) 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Geoff Voelker (voelker@cs.washington.edu)
  6.  
  7. ;; This file is part of GNU Emacs.
  8.  
  9. ;; GNU Emacs is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;; GNU General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  21. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  22. ;; Boston, MA 02111-1307, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; (August 12, 1993)
  27. ;; Created.
  28.  
  29. ;; (November 21, 1994)
  30. ;; [C-M-backspace] defined.
  31. ;; mode-line-format defined to show buffer file type.
  32. ;; audio bell initialized.
  33.  
  34. ;;; Code:
  35.  
  36. ;; Map delete and backspace
  37. (define-key function-key-map [backspace] "\177")
  38. (define-key function-key-map [delete] "\C-d")
  39. (define-key function-key-map [M-backspace] [?\M-\177])
  40. (define-key function-key-map [C-M-backspace] [\C-\M-delete])
  41.  
  42. ;; Show file type (text or binary) on modeline
  43. (setq-default mode-line-format
  44.   (list (purecopy "")
  45.    'mode-line-modified
  46.    'mode-line-buffer-identification
  47.    (purecopy "   ")
  48.    'global-mode-string
  49.    (purecopy "   %[(")
  50.    (purecopy "%t:")
  51.    'mode-name 'mode-line-process 'minor-mode-alist
  52.    (purecopy "%n")
  53.    (purecopy ")%]--")
  54.    (purecopy '(line-number-mode "L%l--"))
  55.    (purecopy '(column-number-mode "C%c--"))
  56.    (purecopy '(-3 . "%p"))
  57.    (purecopy "-%-")))
  58.  
  59. ;; Ignore case on file-name completion
  60. (setq completion-ignore-case t)
  61.  
  62. ;; The cmd.exe shell uses the "/c" switch instead of the "-c" switch
  63. ;; for executing its command line argument (from simple.el).
  64. (setq shell-command-switch "/c")
  65.  
  66. ;; For appending suffixes to directories and files in shell completions.
  67. (add-hook 'shell-mode-hook 
  68.       '(lambda () (setq comint-completion-addsuffix '("\\" . " "))))
  69.  
  70. ;; Use ";" instead of ":" as a path separator (from files.el).
  71. (setq path-separator ";")
  72.  
  73. ;; Set the null device (for compile.el).
  74. (setq grep-null-device "NUL")
  75.  
  76. ;; Set the grep regexp to match entries with drive letters.
  77. (setq grep-regexp-alist
  78.   '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3)))
  79.  
  80. ;; Taken from dos-fn.el ... don't want all that's in the file, maybe
  81. ;; separate it out someday.
  82.  
  83. (defvar file-name-buffer-file-type-alist
  84.   '(
  85.     ("[:/].*config.sys$" . nil)        ; config.sys text
  86.     ("\\.elc$" . t)            ; emacs stuff
  87.     ("\\.\\(obj\\|exe\\|com\\|lib\\|sys\\|chk\\|out\\|bin\\|ico\\|pif\\)$" . t)
  88.                     ; MS-Dos stuff
  89.     ("\\.\\(arc\\|zip\\|pak\\|lzh\\|zoo\\)$" . t)
  90.                     ; Packers
  91.     ("\\.\\(a\\|o\\|tar\\|z\\|gz\\|taz\\)$" . t)
  92.                     ; Unix stuff
  93.     ("\\.tp[ulpw]$" . t)
  94.                     ; Borland Pascal stuff
  95.     )
  96.   "*Alist for distinguishing text files from binary files.
  97. Each element has the form (REGEXP . TYPE), where REGEXP is matched
  98. against the file name, and TYPE is nil for text, t for binary.")
  99.  
  100. (defun find-buffer-file-type (filename)
  101.   (let ((alist file-name-buffer-file-type-alist)
  102.     (found nil)
  103.     (code nil))
  104.     (let ((case-fold-search t))
  105.       (setq filename (file-name-sans-versions filename))
  106.       (while (and (not found) alist)
  107.     (if (string-match (car (car alist)) filename)
  108.         (setq code (cdr (car alist))
  109.           found t))
  110.     (setq alist (cdr alist))))
  111.     (if found
  112.     (cond((memq code '(nil t)) code)
  113.          ((and (symbolp code) (fboundp code))
  114.           (funcall code filename)))
  115.       default-buffer-file-type)))
  116.  
  117. (defun find-file-binary (filename) 
  118.   "Visit file FILENAME and treat it as binary."
  119.   (interactive "FFind file binary: ")
  120.   (let ((file-name-buffer-file-type-alist '(("" . t))))
  121.     (find-file filename)))
  122.  
  123. (defun find-file-text (filename) 
  124.   "Visit file FILENAME and treat it as a text file."
  125.   (interactive "FFind file text: ")
  126.   (let ((file-name-buffer-file-type-alist '(("" . nil))))
  127.     (find-file filename)))
  128.  
  129. (defun find-file-not-found-set-buffer-file-type ()
  130.   (save-excursion
  131.     (set-buffer (current-buffer))
  132.     (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
  133.   nil)
  134.  
  135. ;;; To set the default file type on new files.
  136. (add-hook 'find-file-not-found-hooks 'find-file-not-found-set-buffer-file-type)
  137.  
  138. ;;; For using attached Unix filesystems.
  139. (defun save-to-unix-hook ()
  140.   (save-excursion
  141.     (setq buffer-file-type t))
  142.   nil)
  143.  
  144. (defun revert-from-unix-hook ()
  145.   (save-excursion
  146.     (setq buffer-file-type (find-buffer-file-type (buffer-file-name))))
  147.   nil)
  148.  
  149. ;; Really should provide this capability at the drive letter granularity.
  150. (defun using-unix-filesystems (flag)
  151.   "Read and write files without CR/LF translation, if FLAG is non-nil.
  152. This is in effect assuming the files are on a remote Unix file system.
  153. If FLAG is nil, resume using CR/LF translation as usual."
  154.   (if flag
  155.       (progn
  156.     (add-hook 'write-file-hooks 'save-to-unix-hook)
  157.     (add-hook 'after-save-hook 'revert-from-unix-hook))
  158.     (progn
  159.       (remove-hook 'write-file-hooks 'save-to-unix-hook)
  160.       (remove-hook 'after-save-hook 'revert-from-unix-hook))))
  161.  
  162. ;;; Avoid creating auto-save file names containing invalid characters
  163. ;;; (primarily "*", eg. for the *mail* buffer).
  164. (fset 'original-make-auto-save-file-name
  165.       (symbol-function 'make-auto-save-file-name))
  166.  
  167. (defun make-auto-save-file-name ()
  168.   "Return file name to use for auto-saves of current buffer.
  169. Does not consider `auto-save-visited-file-name' as that variable is checked
  170. before calling this function.  You can redefine this for customization.
  171. See also `auto-save-file-name-p'."
  172.   (let ((name (original-make-auto-save-file-name))
  173.     (start 0))
  174.     ;; destructively replace occurences of * or ? with $
  175.     (while (string-match "[?*]" name start)
  176.       (aset name (match-beginning 0) ?$)
  177.       (setq start (1+ (match-end 0))))
  178.     name))
  179.  
  180. ;;; Fix interface to (X-specific) mouse.el
  181. (defun x-set-selection (type data)
  182.   (or type (setq type 'PRIMARY))
  183.   (put 'x-selections type data))
  184.  
  185. (defun x-get-selection (&optional type data-type)
  186.   (or type (setq type 'PRIMARY))
  187.   (get 'x-selections type))
  188.  
  189. (fmakunbound 'font-menu-add-default)
  190. (global-unset-key [C-down-mouse-1])
  191. (global-unset-key [C-down-mouse-2])
  192. (global-unset-key [C-down-mouse-3])
  193.  
  194. ;;; Set to a system sound if you want a fancy bell.
  195. (set-message-beep nil)
  196.  
  197. ;;; winnt.el ends here
  198.